package lcspm.commands;

import java.util.List;

import lcspm.lib.ConfigHandler;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ConfigCategory;

public class CommandSetWarp
  implements ICommand
{
  public int compareTo(Object arg0)
  {
    return 0;
  }

  public String getCommandName()
  {
    return "setwarp";
  }

  public String getCommandUsage(ICommandSender icommandsender)
  {
    return "/" + getCommandName() + " <name> <ispublic>";
  }

  public List getCommandAliases()
  {
    return null;
  }

  public void processCommand(ICommandSender icommandsender, String[] astring)
  {
    if ((icommandsender instanceof EntityPlayer)) {
      EntityPlayer player = (EntityPlayer)icommandsender;

      String warpName = "";
      boolean isPublic = false;

      switch (astring.length) {
      case 0:
        player.addChatMessage("This command requires a warp name");
        return;
      case 1:
        warpName = astring[0];
        break;
      case 2:
        warpName = astring[0];
        isPublic = Boolean.parseBoolean(astring[1]);
      }

      if ((warpName.equals("list")) || (warpName.equals("home"))) {
        player.addChatMessage("This warp name is not allowed.");
        return;
      }

      if (ConfigHandler.HasCategory(warpName))
      {
    	  player.addChatMessage("This warp name has already been taken");
    	  return;
      }
      
    String coor = String.valueOf(player.posX + "," + player.posY + "," + player.posZ);

    String world = player.worldObj.getWorldInfo().getWorldName();

    ConfigHandler.SetConfig(warpName, coor, player.dimension, world, player.username, isPublic);

    String msgWarp = "as private";

    if (isPublic) {
      msgWarp = "as public";
    }

    player.addChatMessage("Warp saved " + msgWarp);
      
    }
  }

  public boolean canCommandSenderUseCommand(ICommandSender icommandsender)
  {
    return true;
  }

  public List addTabCompletionOptions(ICommandSender icommandsender, String[] astring)
  {
    return null;
  }

  public boolean isUsernameIndex(String[] astring, int i)
  {
    return false;
  }
}